//
//  ArtVideoListVC.m
//  test02
//
//  Created by lzh on 2021/3/11.
//  Copyright © 2021 NO. All rights reserved.
//

#import "ArtVideoListVC.h"
#import <Masonry.h>
#import "ArtPlayView.h"
#import "ArtCeilingView.h"
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]/// rgb颜色转换（16进制->10进制）
#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
#define kMaxNavHeight 64
@interface ArtVideoListVC ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>{
    
   
}
@property(nonatomic,strong)UITableView * myTableView;
@property(nonatomic,strong)ArtPlayView * palyView;
@property (nonatomic,assign)CGFloat offsetHeight;;

@end

@implementation ArtVideoListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.offsetHeight = SCREEN_WIDTH/16*9+112;
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.palyView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.offsetHeight);
        [self.myTableView reloadData];
    });
}

-(UITableView *)myTableView{
    
    if (!_myTableView) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectZero];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.tableHeaderView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        _myTableView.tableHeaderView = self.palyView;
        [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    
    return _myTableView;
}
-(ArtPlayView *)palyView{
    if (!_palyView) {
        _palyView = [[ArtPlayView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.offsetHeight)];
    }
    
    return _palyView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return SCREEN_HEIGHT - 64 - 50;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
     ArtCeilingView *ceilingView = [[ArtCeilingView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    return ceilingView;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //当前y轴偏移量
       CGFloat currentOffsetY  = scrollView.contentOffset.y;
       //临界点偏移量
//       CGFloat criticalPointOffsetY = [self.myTableView rectForSection:0].origin.y - kMaxNavHeight;
       //第一部分: 更改导航栏的背景图的透明度
       CGFloat alpha = 0;
       if (-currentOffsetY <= kMaxNavHeight) {
           alpha = 1;
       } else if ((-currentOffsetY > kMaxNavHeight) && -currentOffsetY < self.offsetHeight) {
           alpha = (self.offsetHeight + currentOffsetY) / (self.offsetHeight - kMaxNavHeight);
       } else {
           alpha = 0;
       }
    self.navigationController.navigationBar.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:alpha];
}



@end
